﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Profile;
using MongoDB.Bson.DefaultSerializer;
using MongoDB.Bson;

namespace Profiling
{
    /// <summary>
    /// Summary description for Class1
    /// </summary>
    [Serializable]
    public class MyProfile : ProfileBase
    {
        public MyProfile()
        { }
        [SettingsAllowAnonymous(false)]
        public string Naam
        {
            get
            {
                return (string)base["Naam"];
            }
            set
            {
                base["Naam"] = value;
            }
        }
        public Version MyVersion
        {
            get
            {
                return (Version)base["MyVersion"];
            }
            set
            {
                base["MyVersion"] = value;
            }
        }

        [SettingsAllowAnonymous(false)]
        public DateTime LastClick
        {
            get
            {
                return (DateTime)base["LastClick"];
            }
            set 
            {
                base["LastClick"] = value;
            }
        }
        [SettingsAllowAnonymous(false)]
        public List<DateTime> Clicks
        {
            get
            {
                return (List<DateTime>)base["Clicks"];
            }
            set
            {
                base["Clicks"] = value;
            }
        }

        public Dictionary<Guid, string> Dict
        {
            get
            {
                return (Dictionary<Guid, string>)base["Dict"] ?? new Dictionary<Guid, string>();
            }
            set 
            {
                base["Dict"] = value;
            }
        }
        public void SetClick()
        {
            this.LastClick = DateTime.Now.ToLocalTime();
            if (Clicks == null)
            {
                Clicks = new List<DateTime>();
            }
            Clicks.Add(LastClick);
            Dict[Guid.NewGuid()] = LastClick.ToShortDateString();
        }

        [SettingsAllowAnonymous(false)]
        public A Hierarchy { get { return (A)base["Hierarchy"]; } set {base["Hierarchy"] = value ;} }

        [BsonIgnoreExtraElements]
        public class A
        {
            static A() 
            { 
                //BsonClassMap.RegisterClassMap<A>(); 
            }
            public A() { }
            [BsonIgnore]
            public string Naam { get; set; }
            [BsonRepresentation(BsonType.Int64)]
            public TimeSpan DiffTime { get; set; }
            public A Child { get; set; }
        }
    }
}